<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        /* 已知父元素宽高的情况  */
        
        .box {
            width: 300px;
            height: 300px;
            border: 1px solid #333;
            box-sizing: border-box;
            position: relative;
        }
        
        .son {
            width: 100px;
            height: 100px;
            border: 1px solid #333;
            box-sizing: border-box;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%)
        }
        
        .box1 {
            width: 300px;
            height: 300px;
            border: 1px solid #333;
            box-sizing: border-box;
            position: relative;
        }
        
        .son1 {
            width: 100px;
            height: 100px;
            border: 1px solid #333;
            box-sizing: border-box;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
        }
    </style>
</head>

<body>
    <!-- 方法一：已知父元素宽高的情况 -->
    <div class="box">
        <div class="son"></div>
    </div>
    <!-- 方法二：位置父元素宽高，可以配合定位跟margin：auto -->
    <div class="box1">
        <div class="son1"></div>
    </div>
</body>

</html>